#include "FloatText.h"
#include "Framework.h"

FloatText* FloatText::ms_Singleton =  NULL;
FloatText::FloatText()
{

}

FloatText::~FloatText()
{

}

bool FloatText::init()
{
	CCSize winSize = CCDirector::sharedDirector()->getWinSize();
	mDesc = CCLabelTTF::create("","Helvetica",12);
	mDesc->setAnchorPoint(ccp(0.5, 1.3));
	mDesc->setPosition(ccp(winSize.width/2, winSize.height/2-70));
	mBg = CCScale9Sprite::create("sprite/bg_21.png");
	mBg->setAnchorPoint(ccp(0.5, 1.0));
	mBg->setPosition(ccp(winSize.width/2, winSize.height/2-70));
	addChild(mBg);
	addChild(mDesc);
	this->setVisible(false);
	Framework::getSingletonPtr()->topLayer->addChild(this);
	return true;
}

void FloatText::playAnim(const char* content)
{
	mDesc->setString(content);
	CCSize bgSize = mDesc->getContentSize();
	bgSize.width += 10;
	bgSize.height += 10;
	mBg->setContentSize(bgSize);
	this->setVisible(true);
	CCSequence* sequence1 = (CCSequence*)CCSequence::create(
		CCFadeIn::create(1),
		CCDelayTime::create(2.5),
		CCFadeOut::create(0.5),
		CCCallFunc::create(this,callfunc_selector(FloatText::playAnimComplete)),
		NULL);
	CCSequence* sequence2 = (CCSequence*)CCSequence::create(
		CCFadeIn::create(1),
		CCDelayTime::create(2.5),
		CCFadeOut::create(0.5),
		NULL);
	mBg->runAction(sequence1);
	mDesc->runAction(sequence2);
	this->setVisible(true);
}
void FloatText::playAnimComplete()
{
	this->setVisible(false);
}

FloatText* FloatText::getSingletonPtr()
{
	if (ms_Singleton == NULL)
		ms_Singleton = FloatText::create();
	return ms_Singleton;
}


